<script setup>
import { computed } from 'vue';

// 接收props
const props = defineProps({
  scale: {
    type: Number,
    required: true
  }
});

// 定义事件
const emit = defineEmits(['zoom-in', 'zoom-out', 'reset-zoom']);

// 计算显示的缩放百分比
const scalePercentage = computed(() => {
  return Math.round(props.scale * 100);
});

// 放大
function zoomIn() {
  emit('zoom-in');
}

// 缩小
function zoomOut() {
  emit('zoom-out');
}

// 重置缩放
function resetZoom() {
  emit('reset-zoom');
}
</script>

<template>
  <div class="zoom-control">
    <button class="zoom-button" @click="zoomOut" title="缩小">
      <span>-</span>
    </button>
    <div class="zoom-display">
      {{ scalePercentage }}%
    </div>
    <button class="zoom-button" @click="zoomIn" title="放大">
      <span>+</span>
    </button>
    <button class="zoom-button reset-button" @click="resetZoom" title="重置缩放">
      <span>1:1</span>
    </button>
  </div>
</template>

<style>
.zoom-control {
  position: absolute;
  bottom: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 5px;
  z-index: 100;
}

.zoom-button {
  width: 30px;
  height: 30px;
  border: 1px solid #ddd;
  background-color: white;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  font-weight: bold;
  transition: background-color 0.2s;
}

.zoom-button:hover {
  background-color: #f0f0f0;
}

.zoom-display {
  margin: 0 10px;
  font-size: 14px;
  min-width: 40px;
  text-align: center;
}

.reset-button {
  margin-left: 5px;
  font-size: 14px;
}
</style>